package com.cqemme.messageservice.receive;

import com.cqemme.comm.constraint.MqNames;
import com.cqemme.comm.po.EmailModelException;
import com.cqemme.comm.utils.JackSonUtils;
import com.cqemme.messageservice.service.SendEmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author amkj
 */
@Component
@Slf4j
public class EmailReceiver {

    @Autowired
    private SendEmailService sendEmailService;

    @RabbitListener(queues = MqNames.SCHOOL_ALL_TO_MESSAGE_SYSTEM_EMAIL)
    public void Receiver(String msg){
        log.info("Recieve:{}", msg);
        try {
            EmailModelException emailModelException = JackSonUtils.strToBean(msg, EmailModelException.class);
            sendEmailService.sendExceptionEmail(emailModelException);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
